﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CRM.Admin.Contracts.Contract.Customer;
using CRM.Admin.Contracts.Dto.Customer;
using CRM.Admin.Contracts.Model.Customer;
using KingsSharp.Common;
using KingsSharp.Common.Data;
using KingsSharp.Core;
using KingsSharp.Core.Data;

namespace CRM.Admin.Services.Service.Customer
{
    public class TechnologyService: ServiceBase, ITechnologyService
    {
        private IRepository<Technology, Guid> TechnologyRepository;
        public TechnologyService(IRepository<Technology, Guid> _TechnologyRepository)
            :base(_TechnologyRepository.UnitOfWork)
        {
            TechnologyRepository = _TechnologyRepository;
        }

        public IQueryable<Technology> Technologys { get { return TechnologyRepository.Entities; } }

        public OperationResult Delete(params Guid[] ids)
        {
            var entitys = TechnologyRepository.Entities.Where(a => ids.Contains(a.Id)).ToList();
            entitys.ForEach(a => a.IsDeleted = true);
            int result = TechnologyRepository.Update(entitys.ToArray());
            return new KingsSharp.Common.Data.OperationResult(KingsSharp.Common.Data.OperationResultType.Success, "删除成功");
        }

        public OperationResult Insert(params TechnologyDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            foreach (var t in dtos)
            {
                t.Id = Guid.NewGuid();
            }
            var result = TechnologyRepository.Insert(dtos);
            return result;
        }

        public OperationResult Update(params TechnologyDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            var result = TechnologyRepository.Update(dtos);
            return result;
        }
    }
}
